<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<base href="<%=basePath%>">
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>WoNiuShop</title>
<link rel="shortcut icon" href="icon.png" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="css/basic.css" />
<link rel="stylesheet" type="text/css" href="css/shopcart.css" />
<link rel="stylesheet" href="css/good.css" type="text/css" />
</head>
<body>
<%@include file="loginandregister.jspf" %>
	<!-- 主要内容 -->
	<div id="balance">
		<!-- 您当期的余额为: <span class="s-money"> ￥10000</span> -->
	</div>
	<table id="lists">
		<tr>
			<th></th>
			<th>商品名称</th>
			<th>单价</th>
			<th>数量</th>
			<th>小计</th>
			<th>操作</th>
		</tr>
		<c:forEach var="cartItem" items="${shopCart.allCartItem}">
		<tr>
			<td class="td-g-img"><img src="${cartItem.goods.goodImgPath}"></td>
			<td>${cartItem.goods.gName}</td>
			<td>${cartItem.goods.price}</td>
			<td><span class="s-btn"><button class="btn1"
									onclick="numMulp(${cartItem.goods.gId})">－</button></span><input type="text" name="num" value="${cartItem.buyCount}"
							disabled="disabled" id="total"/><span class="s-btn"><button
									class="btn1" onclick="numAdd(${cartItem.goods.gId},this.value)">＋</button></span></td>
			<td>${cartItem.subTotalPrice}</td>
			<td><a href="DelCartItemFromShopCartSerlvelt?gid=${cartItem.goods.gId}"><img src="icon/关闭.png"></a></td>
		</tr>
		</c:forEach>
	</table>
	<div id="pay">
		<div class="btn-pay">
			<a href="OrderServlet" class="order-btn btn-danger f-white">生成订单</a>
		</div>
		<div class="total">
			总价为 <span class="s-money">${shopCart.totalPrice}</span>
		</div>
	</div>
	<div id="footer">蜗牛创想科技-woniushop&copy; 版权所有</div>
	<script src="js/jquery.min.js"></script>
	<script src="js/basic.js"></script>
	<script type="text/javascript">
		function numAdd(gId) {
			var $total = $("#total");
			var count = parseInt($total.val());
			$total.val(count + 1);
			var xmlhttp;
			
			if(window.XMLHttpRequest){
				xmlhttp = new XMLHttpRequest();
			}else{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			//发送请求
			console.log("发送ajax"+gId);
			console.log("num:\t"+count);
			xmlhttp.open("GET","ChangeServlet?gid="+gId+"&count="+count,true);
			xmlhttp.send();
			location.reload();
		}
		function numMulp(gId) {
			var $total = $("#total");
			var count1 = parseInt($total.val());
			if (count1 >= 1) {
				$total.val(count1 - 1);
			}
			var xmlhttp;
			
			if(window.XMLHttpRequest){
				xmlhttp = new XMLHttpRequest();
			}else{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			//发送请求
			console.log("发送ajax"+gId);
			console.log("num:\t"+count1);
			xmlhttp.open("GET","ChangeServlet?gid="+gId+"&count1="+count1,true);
			xmlhttp.send();
			location.reload();
		}
		
	</script>
</body>
</html>